#include "QuestionItem.h"
#include "ui_QuestionItem.h"
#include <QDebug>
#include <QPainter>
#include <QFontMetrics>
#include <QResizeEvent>
CQuestionItem::CQuestionItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CQuestionItem)
{
    ui->setupUi(this);
}

CQuestionItem::~CQuestionItem()
{
    delete ui;
}

void CQuestionItem::fillText(int idx,QString text)
{
    ui->label_question->setText(text);
    ui->label_index->setText(QString::number(idx));
}

void CQuestionItem::setHeadIcon(QString iconPath)
{
    QPixmap pixmap;
    pixmap.load(":/head.png");
    QPixmap fitpixmap = pixmap.scaled(80, 80, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_head->setPixmap(fitpixmap);
}

void CQuestionItem::paintEvent(QPaintEvent *event)
{
//    qDebug()<<"paintEvent was called";

}

void CQuestionItem::resizeEvent(QResizeEvent *event)
{
    static long idx = 1;
    ++idx;


    int width = event->size().width();
    int height = ui->label_question->heightForWidth(width-130);
//    ui->label_question->setFixedSize(width-130,height);
//    ui->label_question->setFixedHeight(200);
    ui->label_question->setFixedWidth(width-130);

//    this->setFixedHeight(50+40);
    emit sigItemSizeChanged(width,height);
    qDebug()<<"resizeEvent was called "<<QString::number(idx)<<"calSize:"<<QString::number(width-130)<<","<<QString::number(height);
//    QPainter p(this);
//    QFontMetrics fm = p.fontMetrics();

}
